import { getCouponList } from "@/static/js/my.js";
export default {
  data() {
    return {
      showRules: false, //规则弹窗
      rule: "", //规则
      selectIndex: 0,
      status: "",
      tabList: [
        {
          id: 1,
          name: "默认",
        },
        {
          id: 2,
          name: "已使用",
          status: 1,
        },
        {
          id: 3,
          name: "已过期",
          status: 2,
        },
      ],
      couponList: [],
      customStyle1: {
        width: '350px',
        minHeight: '500rpx',
        padding: '20px',
        textAlign: 'center',
      }
    };
  },
  onLoad() {
    this.getCouponList();
  },
  methods: {
    menuClick(item, index) {
      this.selectIndex = index;
      if (index == 1) {
        this.status = 1;
      } else if (index == 2) {
        this.status = 2;
      } else {
        this.status = "";
      }
      this.getCouponList();
    },
    goUse(item) {
      console.log(item);
      if (item.type == 1) {
        uni.navigateTo({
          url: "/quiz/ask/index",
        });
      } else {
        uni.navigateTo({
          url: "/quiz/expertList/index",
        });
      }
    },

    //获取优惠券列表
    async getCouponList() {
      let res = await getCouponList({
        status: this.status,
      });
      if (res.code == 1) {
        this.couponList = res.data.list;
        this.rule = res.data.rule;
        for (let item of res.data.list) {
          let a = item.endtime * 1000 - new Date().getTime();
          let isToday = a > 0 && a < 24 * 3600 * 1000; //相差在0~一天内
          this.$set(item, "isToday", isToday);
        }
      } else {
        this.$tools.msg(res.msg);
      }
    },
  },
};